package com.smallcr.config;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;

import com.smallcr.interceptor.AuthorizationInterceptor;

@Configuration
@EnableWebMvc
@ComponentScan("com.smallcr.*")
public class WebConfig extends AbstractWebMvcConfig {

	@Bean
	public AuthorizationInterceptor authorizationInterceptor() {
		return new AuthorizationInterceptor();
	}

//	@Autowired
//	private LoginUserHandlerMethodArgumentResolver loginUserHandlerMethodArgumentResolver;
//
//	@Override
//	public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
//		argumentResolvers.add(loginUserHandlerMethodArgumentResolver);
//	}

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		List<String> patterns = new ArrayList<String>();
		// api相关的接口
		patterns.add("/**");
		registry.addInterceptor(authorizationInterceptor())
				.addPathPatterns(patterns.toArray(new String[patterns.size()]));
	}

}
